<template>
    <WModal @ok="ok" v-bind="$attrs" ref="dialogRef">
        <WForm v-bind="$attrs" ref="formRef" @submit="$emit('ok', $event)">
            <template #button>&nbsp;</template>
        </WForm>
    </WModal>
</template>

<script setup>
import { ref } from 'vue';

/**
 * dialog引用
 */
const dialogRef = ref();
/**
 * form引用
 */
const formRef = ref();

const emit = defineEmits(['ok']);

/**
 * OK事件
 */
const ok = async () => {
    try {
        const model = await formRef.value.valid();
        dialogRef.value.start();
        emit('ok', model);
    } catch (error) {
        // 表单验证失败时不需要处理
    }
}

defineExpose({
    show: () => dialogRef.value.show(),
    hide: () => {
        dialogRef.value.stop();
        dialogRef.value.hide();
    },
    start: () => dialogRef.value.start(),
    stop: () => dialogRef.value.stop()
});
</script>

<style lang="scss" scoped>
</style>